package b4.widget.tab
{
	import flash.display.Sprite;
	import flash.text.*;

	public class TabButton extends TabTitle
	{
		private var backgroundImg:Sprite;
		private var highlightBgrImg:Sprite;
		
		public function TabButton(BackgroundImg:Class, title:String, index:int, HighlightBgrImg:Class = null)
		{
			super(index, title);
			backgroundImg = new BackgroundImg();
			addChild(backgroundImg);
			if (HighlightBgrImg != null)
			{
				highlightBgrImg = new HighlightBgrImg();
				addChild(highlightBgrImg);
				highlightBgrImg.visible = false;
			}
			//标题
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 14, 0x000000, true);
			titleText.text = title;
			titleText.x = (backgroundImg.width - titleText.width) / 2;
			titleText.y = (backgroundImg.height - titleText.height) / 2;
			addChild(titleText);
			this.mouseChildren = false;
		}
		
		override public function set highlight(hlight:Boolean):void
		{
			if (highlightBgrImg != null)
			{
				if (hlight)
				{
					backgroundImg.visible = false;
					highlightBgrImg.visible = true;
				}
				else
				{
					backgroundImg.visible = true;
					highlightBgrImg.visible = false;
				}
			}
		}
		
	}
}